import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.fmistuff.chain.nodes.ExprNode;
import com.fmistuff.chain.nodes.MarkovNode;
import com.fmistuff.chain.nodes.NumNode;
import com.fmistuff.chain.nodes.TermNode;

public class ThreadedCalcTest {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testPickANode() {
		Map<String, MarkovNode> pool = new HashMap<String, MarkovNode>();
		pool.put("0", new NumNode("0"));
		pool.put("1", new NumNode("1"));
		pool.put("2", new NumNode("2"));
		pool.put("3", new NumNode("3"));
		pool.put("4", new NumNode("4"));
		pool.put("5", new NumNode("5"));
		pool.put("6", new NumNode("6"));
		pool.put("7", new NumNode("7"));
		pool.put("8", new NumNode("8"));
		pool.put("9", new NumNode("9"));

		boolean results[] = new boolean[10];

		for (int i = 0; i < 100; i++) {
			String resString = MarkovNode.pickANode(pool).getData();
			results[Integer.parseInt(resString)] = true;
		}
		
		for (int i = 0; i < results.length; i++){
			if (results[i]==false){
				fail("Does not give chance to every member");
			}
		}
		
		pool = new HashMap<String, MarkovNode>();
		pool.put("+", new ExprNode("+"));
		pool.put("-", new ExprNode("-"));

		final MarkovNode termNode = new TermNode();
		pool.put("term", termNode);
		
		HashMap<String, MarkovNode> resultsHashMap = new HashMap<String, MarkovNode>();
		for (int i = 0; i < 1000; i++) {
			MarkovNode resNode = MarkovNode.pickANode(pool);
			System.out.println(resNode.getData());
			resultsHashMap.put(resNode.getData(), resNode);
		}
		
		Assert.assertTrue(resultsHashMap.values().containsAll(pool.values()));
		
		
	}
}
